<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="../../js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
  </head>
  
  <body>
    <div class="x-body">
			<table id="Table" lay-filter="test"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
			<a class="layui-btn layui-btn-sm" lay-event="addkey">增加钥匙</a>
		</script>
    <script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="recoud">借出记录</a>
			<a class="layui-btn layui-btn-xs" lay-event="detail">钥匙详情</a>
		</script>
    <script>
   
        layui.use(['table', 'layer'], function() {
					layer = layui.layer;
					table = layui.table;
					
					var data = {enable:1};
	        if(window.location.href.indexOf("?")!=-1){
	        	 var para =  window.location.href.substr(window.location.href.indexOf("?")+1);
	        	 if(para != null && para != undefined && para.trim() != ''){
	        		 para = para.replace(/=/g,"':'");
                     para = para.replace(/&/g,"','");
                     data = $.extend({},data,eval("({'"+para+"'})"));
	                 console.log(data);
	                 console.log(para);
	             }
	        }
        
					table.render({
					    elem: '#Table'
					    ,id: 'keyTable'
					    ,height: 605
					    ,width:800
					    ,url: '../getRoomKeyCount' //数据接口
					    ,where:data
					    ,page: {limits:[10, 20, 30]} //开启分页
					    ,toolbar: '#toolbarDemo' //开启工具栏
					    ,request: {
					   		pageName: 'pageNo' //页码的参数名称，默认：page
					    	,limitName: 'pageSize' //每页数据量的参数名，默认：limit
					  	}
					    ,cols: [[ //表头
					      {field: 'roomName', title: '房间', width:100,  fixed: 'left'}
					      ,{field: 'presonName', title: '房间所属用户', width:150,  fixed: 'left'}
					      ,{field: 'keyCount', title: '备用钥匙数', width:120, sort: true}
					      ,{field: 'lendCount', title: '借出钥匙数', width:120, sort: true}
					      ,{fixed: 'right', title: '操作', width: 160,templet:'#barDemo'}
					    ]]
				   });
					
					//头工具栏事件
					  table.on('toolbar(test)', function(obj){
						  var data = obj.data;
	                        if(obj.event === 'addkey'){
	                            x_admin_show('增加钥匙','./key-add.html');
	                        } 
					  });	
					
					 //监听行工具事件
				table.on('tool(test)', function(obj){
	                    var data = obj.data;
	                    if(obj.event === 'recoud'){
	                    	x_admin_show('钥匙借出记录','./key-record.html?roomId='+data.roomId);
	                    } else if(obj.event === 'detail'){
	                        x_admin_show('房间钥匙详情','./key.html?blgRoomId='+data.roomId);
	                    }
	              
	            });
	   
      });
    </script>

  </body>

</html>